import {useNavStore} from '@/store/index.js'
import siteinfo from '@/siteinfo.js'
// #ifdef H5
const baseURL = "/api"
// #endif
// #ifndef H5
const baseURL = siteinfo.siteinfo.baseurl//基础路径
// #endif


let header = {
		'Content-Type': 'application/json',
		'App-coordinate': "0,0",
}

export default (url, data = {}, method = 'POST') => {
	var token = uni.getStorageSync('access_token') ||''
	header['Authorization'] =`Bearer ${token}`
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL + url,
			data,
			method,
			header,
			success: (res) => {
				
				if(res.data.code==401||res.data.code==500){
					uni.showToast({
						title:res.data.msg,
						icon:'none',
						duration:1000
					})
					uni.reLaunch({
						url:'/pages-login/login/login'
					})
					return
				}
				resolve(res.data);
				setTimeout(() => {
					uni.hideLoading();
				}, 200)
				uni.stopPullDownRefresh()
				// console.log(url.split('/').splice(2, 1), res)
			},
			fail: (err) => {
				// console.log('请求失败:', err);
				reject(err)
				uni.hideLoading();
				uni.stopPullDownRefresh()
			},
		})
	})
}


// lll() {
// 	gameListApi({
// 		limit: 8,
// 		page: 1
// 	}).then(res => {
// 		console.log(res, 'lllapi');
// 	})
// },